package com.zareal.feign;

import com.zareal.enums.GlobalErrorCode;
import com.zareal.result.JSONResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ProductFeignClientFallbackFactory implements FallbackFactory<ProductFeignClient> {
    @Override
    public ProductFeignClient create(Throwable throwable) {
        throwable.printStackTrace();
        log.error("商品查询失败");
        return new ProductFeignClient() {
            @Override
            public JSONResult list() {
                JSONResult jsonResult = new JSONResult();
                return JSONResult.success(GlobalErrorCode.SERVICE_ERROR);
            }

            @Override
            public JSONResult get(Long id) {
                return JSONResult.success(GlobalErrorCode.SERVICE_ERROR);
            }
        };
    }
}
